﻿using BusinessLogic;
using Common;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AppAdmin.Controllers
{
    public class WXUserController : Controller
    {
        //
        // GET: /WXUser/

        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult GetGridJson(Pagination pagination,string UserName, string UserTel, string StartTime, string EndTime)
        {
            var expression = ExtLinq.True<UserInfo>();
            expression = expression.And(t => t.IsDelete == 0);
            expression = expression.And(t => t.UserType == 1);
            if (!string.IsNullOrEmpty(UserName))
            {
                expression = expression.And(t => t.Nickname.Contains(UserName.Trim()));
            }
            if (!string.IsNullOrEmpty(UserTel))
            {
                expression = expression.And(t => t.Tel.Contains(UserTel.Trim()));
            }
            if (!string.IsNullOrEmpty(StartTime))
            {
                var tem = Convert.ToDateTime(StartTime);
                expression = expression.And(t => t.AddTime> tem);
            }
            if (!string.IsNullOrEmpty(EndTime))
            {
                var tem = Convert.ToDateTime(EndTime).AddDays(1);
                expression = expression.And(t => t.AddTime< tem);
            }
            int Total = 0;
            var list = new WXUserLogic().getPageDate<UserInfo, DateTime?>(c => new { c.ID, c.Openid, c.Nickname, c.Sex, c.Language, c.City, c.Province, c.Country, c.Headimgurl, c.AddTime, c.Tel, c.Status, c.IsDelete, c.LastLoginTime, c.AttentionTime, c.UserType }, expression, c => c.AddTime, pagination.page, pagination.rows, out Total);
            pagination.records = Total;
            var data = new
            {
                rows = list,
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }


        public ActionResult DeleteForm(string keyValue)
        {
            WXUserLogic bll = new WXUserLogic();
            bll.DelInfo(keyValue);
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = "删除成功。" }.ToJson());
        }
        public ActionResult Agree(string keyValue)
        {
            WXUserLogic bll = new WXUserLogic();
            bll.UnLock(keyValue);
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = "操作成功。" }.ToJson());
        }
        public ActionResult Refuse(string keyValue)
        {
            WXUserLogic bll = new WXUserLogic();
            bll.Lock(keyValue);
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = "操作成功。" }.ToJson());
        }
        public ActionResult SetToStyle(string keyValue)
        {
            WXUserLogic bll = new WXUserLogic();
          int result=  bll.SetToStyle(keyValue);
          return Content(new AjaxResult { state = result, message = "操作成功。" }.ToJson());
        }
    }
}
